<?php
namespace app\common\model;
use x\Xbase;
class Recharge extends Xbase
{
    /**
     * 在线充值
     * [rechargeMoney description]
     * @return [type] [description]
     */
    public function add($user_id,$money,$paytype,$note,$tab='',$tab_id=0,$tab_order_no=''){
        $fee = 0;//手续费
        $real_money = $money - $fee;//到账金额
        $order_no = com_order_no();
        $data = [
            "user_id" => $user_id,
            "order_no" => $order_no,
            "money" => $money,
            "fee" => $fee,
            "pay_type" => $paytype,
            "real_money" => $real_money,
            "tab" => $tab,
            "tab_id" => $tab_id,
            "tab_order_no" => $tab_order_no,
            'note' => $note,
            "create_time" => time()
        ];
        $id = $this->db->insert('recharge',$data);
        if(!$id){
            return $this->setError('创建充值订单失败');
        }

        return $order_no;
    }


    //获取充值单关联表信息
    public function getRechargeTableInfo($order_no){
        $map = [];
        $map[] = ["and",'order_no',"=",$order_no];
        $w = where($map);
        $recharge_info = $this->db->query("select * from recharge $w[0]",$w[1]);
        $rs = $this->db->find($recharge_info[0]['tab'],$recharge_info[0]['tab_id']);
        return $rs;
    }
}
